import Vue from 'vue'
import Vuex from 'vuex'
import {getStorage, setStorage} from '@/utils/storage'

Vue.use(Vuex)

const TOKEN = 'user'

const state = {
  user: getStorage(TOKEN) || {}
}

const mutations = {
  setUser(state, user) {
    state.user = user

    setStorage(TOKEN, user)
  }
}

const store = new Vuex.Store({
  state,
  mutations
})

export default store
